/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var errorContainer;
var controlContainer;
function ManagementComment(){
}

ManagementComment.prototype.initController=function(pErrorContainer,pControlContainer){
    errorContainer=pErrorContainer;
    controlContainer=pControlContainer;
}
ManagementComment.prototype.initDefaultController=function(pControlContainer){
    controlContainer=pControlContainer;
}

var xmlDoc;
ManagementComment.prototype.deleteComment=function (comid,proid){
    var xmlhttp;
    var data="action=COMMENT_DELETE&comid="+comid + "&proid="+proid;
    xmlhttp=getXmlHttpObj();
    xmlhttp.open("GET",contextPath+"/CommentController?"+data,true);
    xmlhttp.send();
    xmlhttp.onreadystatechange=function(e){
        var current=e.target;
        if (current.readyState==4 && current.status==200)
        {
            var errorXml=xmlhttp.responseXML;
            
            errorContainer.innerHTML="";

            if(errorXml){
                errorContainer.innerHTML=xmlhttp.responseXML.getElementsByTagName("error")[0].textContent.fontcolor("red");
            }else{
                var resString=xmlhttp.responseText;
                
                controlContainer.innerHTML=resString;
            }
        }
    }

}

ManagementComment.prototype.saveNewComment=function(uid,proid,containtext,errorContainer,controlContainer){
    var xmlhttp;
    var data="action=COMMENT_ADD&uid="+uid +"&proid="+proid +"&containtext="+containtext.value;

    xmlhttp=getXmlHttpObj();
    xmlhttp.open("GET",contextPath+"/CommentController?"+data,true);
    xmlhttp.send();
    xmlhttp.onreadystatechange=function(e){
        var current=e.target;
        if (current.readyState==4 && current.status==200)
        {
            var errorXml=xmlhttp.responseXML;

            errorContainer.innerHTML="";

            if(errorXml){
                errorContainer.innerHTML=xmlhttp.responseXML.getElementsByTagName("error")[0].textContent.fontcolor("red");
            }else{
                var resString=xmlhttp.responseText;

                controlContainer.innerHTML=resString;
            }
        }
    }


}
function saveNewComment(){
    var xmlhttp;
    var tUserId=document.getElementById("txtName");
    var tRestaurantId=document.getElementById("txtRestaurantId");
    var tComment=document.getElementById("txtComment");
    var tRating=document.getElementById("txtRating");


    var data="action=COMMENT_ADD&userid="+tUserId.value
    +"&restaurantid="+tRestaurantId.value
    +"&comment="+tComment.value
    +"&rating="+tRating.value;
    xmlhttp=getXmlHttpObj();
    xmlhttp.open("GET",contextPath+"/CommentController?"+data,true);
    xmlhttp.send();
    xmlhttp.onreadystatechange=function(e){
        var current=e.target;
        if (current.readyState==4 && current.status==200)
        {
            var errorXml=xmlhttp.responseXML;
            var errorContainer=document.getElementById("ErrorContainer");
            errorContainer.innerHTML="";

            if(errorXml){
                errorContainer.innerHTML=xmlhttp.responseXML.getElementsByTagName("error")[0].textContent.fontcolor("red");
            }else{
                var resString=xmlhttp.responseText;
                var containerElement=document.getElementById("CommentContainer");
                containerElement.innerHTML=resString;
            }
        }
    }


}

